package com.lancer.cloud.common.enums;

/**
 * 用户状态枚举
 *
 * @author caijinbang
 * @date 2019-06-18 13:28
 */
public enum  UserStatusEnum {

    /**
     * 正常
     */
    NORMAL(0,"NORMAL", "正常"),

    /**
     * 锁定
     */
    LOCK(1,"LOCK","锁定");


    private Integer code;

    private String name;

    private String message;

    UserStatusEnum(Integer code, String name, String message) {
        this.code = code;
        this.name = name;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMessage() {
        return message;
    }


    /**
     * 判断枚举值是否存在
     */
    public static boolean isExist(Integer value) {
        if (value == null) {
            return false;
        }
        for (UserStatusEnum e : values()) {
            if (value.equals(e.getCode())) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据枚举值获取其对应的名字
     * @param code
     * @return
     */
    public static UserStatusEnum getEnumByCode(Integer code) {
        UserStatusEnum codeEnum = null;
        for (UserStatusEnum e : UserStatusEnum.values()) {
            if (code.equals(e.getCode())) {
                codeEnum = e;
                break;
            }
        }
        return codeEnum;
    }


    /**
     * 根据枚举值获取其对应的名字
     * @param code
     * @return
     */
    public static String getNameByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for (UserStatusEnum e : UserStatusEnum.values()) {
            if (code.equals(e.getCode())) {
                return e.getName();
            }
        }
        return "";
    }

    /**
     * 根据枚举值获取其对应的名字
     * @param code
     * @return
     */
    public static String getMessageByCode(Integer code) {
        String message = "";
        if (code != null) {
            for (UserStatusEnum e : UserStatusEnum.values()) {
                if (code.equals(e.getCode())) {
                    message = e.getMessage();
                }
            }
        }
        return message;
    }
}
